package com.bwie.House.controller;


import com.bwie.House.config.OSSFileUtil;
import com.bwie.House.service.OldhouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bwie.house.entity.OldhouseEntity;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author wangmo
 * @email wangmo@gmail.com
 * @date 2021-10-13 19:50:25
 */
@RestController
@RequestMapping("house/oldhouse")
//@CrossOrigin
public class OldhouseController {
    @Autowired
    private OldhouseService oldhouseService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = oldhouseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{oldHouseid}")
    public R info(@PathVariable("oldHouseid") Integer oldHouseid){
		OldhouseEntity oldhouse = oldhouseService.getById(oldHouseid);

        return R.ok().put("oldhouse", oldhouse);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OldhouseEntity oldhouse){
		oldhouseService.save(oldhouse);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OldhouseEntity oldhouse){
		oldhouseService.updateById(oldhouse);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] oldHouseids){
		oldhouseService.removeByIds(Arrays.asList(oldHouseids));

        return R.ok();
    }

    @PostMapping("/upload")
    public String upload(MultipartFile file) throws IOException {
        String s = OSSFileUtil.uploadFile(file);
        return s;
    }

}
